﻿@model XoohooViewModelItem<ModuleSubMenuItemList>
@{var sm = Model.Item;}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>@Html.SiteTitle(Model.Item.Title)</title>
    @{Html.RenderCssFile("Styles/SubMenu.css");}
    @{Html.RenderScriptTag("Scripts/jquery.min.js");}
</head>
<body>
    <div id="subMenu">
        <ul>
            @{
                //SubMenu在此只实现了二级，如果有需求，往下扩展或改为递归皆可
                bool isUrl;
                foreach (var item in sm)
                {
                    WriteLiteral("<li class=\"MenuLevel{0}\">".FormatWith(item.MenuLevel));

                    if (item is ModuleSubMenuItemSingle)
                    {
                        var singleItem = item as ModuleSubMenuItemSingle;
                        isUrl = !singleItem.ContentRouteName.IsNullOrEmpty();

                        WriteLiteral("<a href=\"{0}\" {1}>{2}</a>".FormatWith(isUrl ? Url.RouteUrl(singleItem.ContentRouteName, singleItem.RouteValues) : "javascript:;", isUrl ? "target=\"frmContent\"" : String.Empty, singleItem.Title));
                    }
                    else if (item is ModuleSubMenuItemGroup)
                    {
                        var groupItem = item as ModuleSubMenuItemGroup;

                        WriteLiteral("<ul>");
                        bool isSubUrl;
                        foreach (var it in groupItem.Items)
                        {
                            var sit = it as ModuleSubMenuItemSingle;
                            if (sit != null)
                            {
                                isSubUrl = !sit.ContentRouteName.IsNullOrEmpty();
                                WriteLiteral("<li><a href=\"{0}\" {1}>{2}</a></li>".FormatWith(isSubUrl ? Url.RouteUrl(sit.ContentRouteName, sit.RouteValues) : "javascript:;", isSubUrl ? "target=\"frmContent\"" : String.Empty, sit.Title));
                            }
                        }
                        WriteLiteral("</ul>");
                    }

                    WriteLiteral("</li>");
                }
            }
        </ul>
    </div>
</body>
</html>
